import pandas as pd
import numpy as np

# 初始化数组
np.random.seed(1)
X = np.random.randint(1, 10, size=30)

# 改为3列的矩阵
X = X.reshape(-1,3)
print(X)
print('*'*50)

# 将第三列中，小于等于3的修改为0、大于3且小于等于6的修改为1、大于6的修改为2
X[:,2] = np.where(X[:,2] <3 , 0 ,X[:,2])
X[:,2] = np.where(X[:,2] >6 , 2 ,X[:,2])
X[:,2] = np.where(((X[:,2] >3)&(X[:,2] <= 6)) , 1 ,X[:,2])

print(X)

# 分离矩阵
X_train,y_train = np.split(X,[2],axis = 1)
print('X_train: ',X_train)
print('y_train: ',y_train)
print('-'*50)

# 通过 y_train 中的数据，分离出 X_train 中的 3 个分类
# 将多维数组转化为一维数组
y_train = y_train.flatten()
# 分类为0的样本
result_1 = X_train[y_train == 0]
print('分类为0的样本')
print(result_1)


# 分类为1的样本
result_2 = X_train[y_train == 1]
print('分类为1的样本')
print(result_2)


# 分类为2的样本
result_3 = X_train[y_train == 2]
print('分类为2的样本')
print(result_3)